package kr.pe.johnkim.pushchat.mobile.controller;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatRecommendation;
import kr.pe.johnkim.pushchat.mobile.service.PushChatRecommendationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 일기의 좋아요(추천)에 관련된 controller class 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 9. 6.
 */
@Controller
@RequestMapping(value = "/pushChatRecommendationController")
public class PushChatRecommendationController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatRecognitionController.class);

    @Autowired
    private PushChatRecommendationService pushChatRecommendationService;

    /**
     * 좋아요 중복을 확인 한다.
     *
     * @param pushChatRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectDuplicationRecommendation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatRecommendation selectDuplicationRecommendation(@RequestBody PushChatRecommendation pushChatRecommendation) throws Exception {
        logger.info("selectDuplicationRecommendation");

        return this.pushChatRecommendationService.selectDuplicationRecommendation(pushChatRecommendation);
    }

    /**
     * 좋아요를 등록 한다.
     *
     * @param pushChatRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/registerRecommendation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatRecommendation registerRecommendation(@RequestBody PushChatRecommendation pushChatRecommendation) throws Exception {
        logger.info("registerRecommendation");

        PushChatRecommendation result = new PushChatRecommendation();

        try {
            this.pushChatRecommendationService.registerRecommendation(pushChatRecommendation);
            result.setResult("SUCCESS");
            logger.info("success to register diary recommendation.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to register diary recommendation.");
        }

        return result;
    }
}
